package com.laiketui.admin.mch.plugin;

import com.laiketui.admin.mch.api.plugin.AuctionService;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.domain.vo.plugin.auction.AddAuctionConfigVo;
import com.laiketui.domain.vo.plugin.auction.AddAuctionVo;
import com.laiketui.root.annotation.HttpApiMethod;
import com.laiketui.core.domain.Result;
import com.laiketui.core.exception.LaiKeAPIException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 竞拍后台管理
 *
 * @author Trick
 * @date 2021/5/14 11:59
 */
@Api(tags = "竞拍后台管理")
@RestController
@RequestMapping("/pc/auction")
public class AuctionController {

    @Autowired
    private AuctionService auctionService;


    @ApiOperation("竞拍后台管理首页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsName", value = "活动标题", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "status", value = "活动状态", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "id", value = "竞拍活动商品id", dataType = "int", paramType = "form")
    })
    @PostMapping("/index")
    @HttpApiMethod(urlMapping = "pc.admin.auction.index")
    public Result index(MainVo vo, String goodsName, Integer status, Integer id) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.index(vo, goodsName, status, id));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("获取竞拍商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", value = "商品类型id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "brandId", value = "品牌id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "title", value = "商品名称", dataType = "int", paramType = "form")
    })
    @PostMapping("/getAuctionGoods")
    @HttpApiMethod(urlMapping = "pc.admin.auction.getAuctionGoods")
    public Result getAuctionGoods(MainVo vo, Integer classId, Integer brandId, String title) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.getAuctionGoods(vo, classId, brandId, title));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("编辑竞拍商品-加载数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "竞拍活动商品id", dataType = "int", paramType = "form")
    })
    @PostMapping("/auctionDetail")
    @HttpApiMethod(urlMapping = "pc.admin.auction.auctionDetail")
    public Result auctionDetail(MainVo vo, int id) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.auctionDetail(vo, id));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("添加/编辑竞拍商品")
    @PostMapping("/addAuction")
    @HttpApiMethod(urlMapping = "pc.admin.auction.addAuction")
    public Result addAuction(AddAuctionVo vo) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.addAuction(vo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("竞拍是否显示开关")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "竞拍活动商品id", dataType = "int", paramType = "form")
    })
    @PostMapping("/showSwitch")
    @HttpApiMethod(urlMapping = "pc.admin.auction.showSwitch")
    public Result showSwitch(MainVo vo, Integer id) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.showSwitch(vo, id));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("竞拍明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "竞拍活动商品id", dataType = "int", paramType = "form")
    })
    @PostMapping("/getAcutionDetail")
    @HttpApiMethod(urlMapping = "pc.admin.auction.getAcutionDetail")
    public Result getAcutionDetail(MainVo vo, int id, String name, Integer userId) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.getAcutionDetail(vo, id, name, userId));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("删除竞拍商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "竞拍活动商品id", dataType = "string", paramType = "form")
    })
    @PostMapping("/del")
    @HttpApiMethod(urlMapping = "pc.admin.auction.del")
    public Result del(MainVo vo, String ids) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.del(vo, ids));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("开始，结束活动")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "竞拍活动商品id", dataType = "int", paramType = "form")
    })
    @PostMapping("/siwtch")
    @HttpApiMethod(urlMapping = "pc.admin.auction.siwtch")
    public Result siwtch(MainVo vo, Integer id) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.siwtch(vo, id));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("保证金列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "竞拍活动商品id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "userName", value = "用户名称/id", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "type", value = "1=缴纳 2=退回", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "form")
    })
    @PostMapping("/promiseList")
    @HttpApiMethod(urlMapping = "pc.admin.auction.promiseList")
    public Result promiseList(MainVo vo, String userName, Integer type, String startDate, String endDate) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.promiseList(vo, userName, type, startDate, endDate));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("获取竞拍设置")
    @PostMapping("/config")
    @HttpApiMethod(urlMapping = "pc.admin.auction.config")
    public Result config(MainVo vo) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.config(vo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("添加/编辑竞拍配置")
    @PostMapping("/addConfig")
    @HttpApiMethod(urlMapping = "pc.admin.auction.addConfig")
    public Result addConfig(AddAuctionConfigVo vo) throws LaiKeAPIException {
        try {
            return Result.success(auctionService.addConfig(vo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

}
